//
//  MyInviteTableViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/6/11.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "MyInviteTableViewController.h"
#import "HWDownSelectedView.h"
#import "WHCView.h"

#import "CommissionRecordTableViewController.h"
#import "InviteRecoedTableViewController.h"

#import "InviteView.h"

#import "MJRefresh.h"
#import "XTNetReloader.h"
#import "WeChatStylePlaceHolder.h"

#import "InviteModel.h"
#import "CommissionModel.h"
#import "CommissionRecordModel.h"

#import "InviteRecordCell.h"
#import "CommissionRecordCell.h"

#import "RuleViewController.h"
#import "BillboardListViewController.h"
#define WEAKSELF   __typeof(&*self) __weak weakSelf = self;
@interface MyInviteTableViewController ()<HWDownSelectedViewDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *headV;
//@property (weak, nonatomic) IBOutlet HWDownSelectedView *timeSelectedView;
//@property (weak, nonatomic) IBOutlet HWDownSelectedView *statusSelectedView;
@property (weak, nonatomic) IBOutlet UILabel *directLabel;
@property (weak, nonatomic) IBOutlet UILabel *indirectLabel;
@property (weak, nonatomic) IBOutlet UILabel *commissionDiscountAmountLabel;
@property (weak, nonatomic) IBOutlet UILabel *oneUserAccountLabel;
@property (weak, nonatomic) IBOutlet UILabel *twoUserAccountLabel;
@property (weak, nonatomic) IBOutlet UILabel *threeUserAccountLabel;
@property (weak, nonatomic) IBOutlet UILabel *onecommissionDiscountAmountLabel;
@property (weak, nonatomic) IBOutlet UILabel *twocommissionDiscountAmountLabel;
@property (weak, nonatomic) IBOutlet UILabel *threecommissionDiscountAmountLabel;

@property (nonatomic, weak) HWDownSelectedView *timeSelectedView;
@property (nonatomic, weak) HWDownSelectedView *statusSelectedView;

@property (nullable ,nonatomic , strong) UIScrollView *scrollView;
@property (nonatomic, strong)WHCView *topview;
// 添加 子VC 到数组
@property (nullable ,nonatomic, copy) NSArray<__kindof UIViewController *> *homeScrollViews;

@property (nonatomic, strong) InviteView *inviteView;

@property (nonatomic, assign) NSInteger dataCount;      /** 数据源总数 */
@property (nonatomic, assign) NSInteger pageCount;      /** 每次返回的个数 */

@property (nonatomic, strong) NSString *emptyNotice;

@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic) NSInteger pageNo;
@property (nonatomic) NSInteger pageSize;


@property (nonatomic, assign) NSInteger selectedTag;//0邀请记录  1返佣记录
@property (nonatomic, strong) MJRefreshAutoNormalFooter *footer;
@property (nonatomic, strong) MJRefreshAutoNormalFooter *nilFooter;

@property (weak, nonatomic) IBOutlet UITableView *recordTV;


@property (nonatomic, strong) NSString *rule;//规则说明
@end

@implementation MyInviteTableViewController
- (NSMutableArray *)dataArray {
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.pageNo=1;
    self.pageSize=15;
    self.recordTV.delegate=self;
    self.recordTV.dataSource=self;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh) name:@"ProductComment" object:nil];
    
    
    
    self.headV.frame=CGRectMake(0, 0, ScreenWidth, ScreenHeight+431);
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowleft-icon"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = back;
    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor]; //加上背景颜色，方便观察Button的大小
    //设置图片
    UIImage *imageForButton = [UIImage imageNamed:@"rule-icon"];
    [button setImage:imageForButton forState:UIControlStateNormal];
    //设置文字
    NSString *buttonTitleStr = @"规则";
    [button setTitle:buttonTitleStr forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    [button setTitleColor:RGBColor(115, 117, 130) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0 , 50, 17);
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = barButtonItem;
    
    HWDownSelectedView *down = [HWDownSelectedView new];
    down.backgroundColor = [UIColor clearColor];
    down.textColor = [UIColor colorWithHexString:@"#999999"];
    down.font = [UIFont boldSystemFontOfSize:12];
    down.placeholder = @"全部时间";
    down.listArray = @[@"全部时间", @"近一周", @"近一月", @"近三个月", @"近半年", @"近一年"];
    down.frame = CGRectMake(ScreenWidth-200, 390, 100, 36);
    down.layer.borderWidth = 1;
    down.layer.borderColor = RGBColor(46, 49, 69).CGColor;
    self.timeSelectedView = down;
    [self.headV addSubview:self.timeSelectedView];
    self.timeSelectedView.delegate=self;
    
//    self.timeSelectedView.placeholder = @"全部时间";
//    self.timeSelectedView.backgroundColor=[UIColor clearColor];
//    self.timeSelectedView.textColor = [UIColor colorWithHexString:@"#999999"];
//    self.timeSelectedView.font = [UIFont boldSystemFontOfSize:12];
//    self.timeSelectedView.listArray = @[@"全部时间", @"近一周", @"近一月", @"近三个月", @"近半年", @"近一年"];
//    self.timeSelectedView.delegate=self;
    
    HWDownSelectedView *statusSelectedView = [HWDownSelectedView new];
    statusSelectedView.backgroundColor = [UIColor clearColor];
    statusSelectedView.textColor = [UIColor colorWithHexString:@"#999999"];
    statusSelectedView.font = [UIFont boldSystemFontOfSize:12];
    statusSelectedView.placeholder = @"全部";
    statusSelectedView.listArray =  @[@"全部",@"已生效", @"未生效"];
    statusSelectedView.frame = CGRectMake(ScreenWidth-100, 390, 80, 36);
    statusSelectedView.layer.borderWidth = 1;
    statusSelectedView.layer.borderColor = RGBColor(46, 49, 69).CGColor;
    self.statusSelectedView = statusSelectedView;
    [self.headV addSubview:self.statusSelectedView];
    self.statusSelectedView.delegate=self;
    
//    self.statusSelectedView.placeholder = @"全部";
//    self.statusSelectedView.backgroundColor=[UIColor clearColor];
//    self.statusSelectedView.textColor = [UIColor colorWithHexString:@"#999999"];
//    self.statusSelectedView.font = [UIFont boldSystemFontOfSize:12];
//    self.statusSelectedView.listArray = @[@"全部",@"已失效", @"生效中"];
//    self.statusSelectedView.delegate=self;
    
    [self.headV addSubview:self.topview];
//    [self.headV addSubview:self.scrollView];
    
    
    
    //邀请记录
    [self requstInviteRecordData];
    
    //返佣合计折算金额
    [self getCommissionDiscountRecord];
    
    //返佣榜单前三名
    [self getCommissionDiscountBillboard];
    
}
-(void)viewWillAppear:(BOOL)animated{
    //邀请码 直接邀请人数 间接邀请人数
    [self requstInviteData];
}


- (void)getCommissionDiscountBillboard{
    
    
    [LSRequestManager postRequestWithURL:MARKET(@"getCommissionDiscountBillboard")
                                  params:nil
                                 success:^(NSDictionary *responseData) {
                                     if ([responseData[@"ret"] integerValue ] == 0) {
                                         
                                         NSArray *array = [CommissionModel mj_objectArrayWithKeyValuesArray:responseData[@"data"]];
                                         if (array.count==3) {
                                             CommissionModel*commissionModel=array[0];
                                             self.oneUserAccountLabel.text=commissionModel.userAccount;
                                             self.onecommissionDiscountAmountLabel.text=[NSString stringWithFormat:@"%@ %@",commissionModel.commissionDiscountAmount,commissionModel.commissionDiscountUnit];
                                             
                                             CommissionModel*commissionModel1=array[1];
                                             self.twoUserAccountLabel.text=commissionModel1.userAccount;
                                             self.twocommissionDiscountAmountLabel.text=[NSString stringWithFormat:@"%@ %@",commissionModel1.commissionDiscountAmount,commissionModel1.commissionDiscountUnit];
                                             
                                             CommissionModel*commissionModel2=array[2];
                                             self.threeUserAccountLabel.text=commissionModel2.userAccount;
                                             self.threecommissionDiscountAmountLabel.text=[NSString stringWithFormat:@"%@ %@",commissionModel2.commissionDiscountAmount,commissionModel2.commissionDiscountUnit];
                                         }
                                         
                                         
                                     } else {
                                         self.oneUserAccountLabel.text=@"";
                                         self.onecommissionDiscountAmountLabel.text=@"";
                                         self.twoUserAccountLabel.text=@"";
                                         self.twocommissionDiscountAmountLabel.text=@"";
                                         self.threeUserAccountLabel.text=@"";
                                         self.threecommissionDiscountAmountLabel.text=@"";
                                         [MBProgressHUD showError:responseData[@"msg"]];
                                     }
                                 }
                                 failure:^(NSError *error) {
                                     self.oneUserAccountLabel.text=@"";
                                     self.onecommissionDiscountAmountLabel.text=@"";
                                     self.twoUserAccountLabel.text=@"";
                                     self.twocommissionDiscountAmountLabel.text=@"";
                                     self.threeUserAccountLabel.text=@"";
                                     self.threecommissionDiscountAmountLabel.text=@"";
                                 }
                                 showHUD:NO];
    
    
    
    
}
- (void)getCommissionDiscountRecord{
    NSDictionary *param= @{@"userId":self.useId,
                           @"commissionDiscountTime":@"0",
                           @"commissionDiscountStatus":@"0",
                           @"pageNum":@(self.pageNo),
                           @"pageSize":@(self.pageSize),
                           
                           };
    [LSRequestManager postRequestWithURL:MARKET(@"getCommissionDiscountRecord")
                                 params:param
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        
                                        self.commissionDiscountAmountLabel.text=[NSString stringWithFormat:@"%@",responseData[@"data"][@"commissionDiscountAmount"]];
                                        
                                        
                                        
                                    } else {
                                        self.commissionDiscountAmountLabel.text=@"";
                                        [MBProgressHUD showError:responseData[@"msg"]];
                                    }
                                }
                                failure:^(NSError *error) {
                                    self.commissionDiscountAmountLabel.text=@"";
                                }
                                showHUD:NO];
}
- (void)requstInviteRecordData{
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(beginToRequestInviteData)];
    //    [footer setTitle:@"点击或下拉加载更多" forState:MJRefreshStateIdle];
    [footer setTitle:@"加载中" forState:MJRefreshStateRefreshing];
    footer.stateLabel.textColor = RGBColor(153, 153, 153);
    self.footer = footer;
    NSString*invite_status;
    if ([self.statusSelectedView.text isEqualToString:@"全部"]) {
        invite_status=@"3";
    }else if ([self.statusSelectedView.text isEqualToString:@"已生效"]){
        invite_status=@"1";
    }else if ([self.statusSelectedView.text isEqualToString:@"未生效"]){
        invite_status=@"0";
    }else{
        invite_status=@"3";
    }
    NSString*date;
    if ([self.timeSelectedView.text isEqualToString:@"全部"]) {
        date=@"0";
    }else if ([self.timeSelectedView.text isEqualToString:@"近半年"]){
        date=@"1";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一个月"]){
        date=@"2";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一周"]){
        date=@"3";
    }else if ([self.timeSelectedView.text isEqualToString:@"近三个月"]){
        date=@"4";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一年"]){
        date=@"5";
    }else{
        date=@"0";
    }
    NSDictionary *param= @{@"page":@(self.pageNo),
                           @"page_size":@(self.pageSize),
                           @"invite_status":invite_status,
                           @"date":date,
                           @"display":@"1",
                           
                           };
    [LSRequestManager getRequestWithURL:HUOBI(@"index.php/api/activity/inviteRecord")
                                 params:param
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        if (self.pageNo==1) {
                                            [self.dataArray removeAllObjects];
                                        }
                                        NSArray *array = [InviteModel mj_objectArrayWithKeyValuesArray:responseData[@"data"][@"list"]];
                                        [self.dataArray addObjectsFromArray:array];
                                        if (array.count < self.pageSize) {
                                            self.recordTV.mj_footer = self.nilFooter;
                                        } else {
                                            self.recordTV.mj_footer = self.footer;
                                            //                                            self.footer.refreshingTitleHidden = YES;
                                        }
                                        [self.recordTV.mj_footer endRefreshing];
                                        [self.recordTV reloadData];
                                        
                                        
                                        
                                        
                                    } else {
                                        [self.dataArray removeAllObjects];
                                        self.recordTV.mj_footer = self.nilFooter;
                                        [self.recordTV reloadData];
                                        [MBProgressHUD showError:responseData[@"msg"]];
                                    }
                                }
                                failure:^(NSError *error) {
                                    [self.dataArray removeAllObjects];
                                    self.recordTV.mj_footer = self.nilFooter;
                                    [self.recordTV reloadData];
                                }
                                showHUD:NO];
}

- (void)beginToRequestInviteData{
    self.pageNo++;
    [self requstInviteRecordData];
}
- (void)requstInviteData{
    NSString*invite_status;
    if ([self.statusSelectedView.text isEqualToString:@"全部"]) {
        invite_status=@"3";
    }else if ([self.statusSelectedView.text isEqualToString:@"已生效"]){
        invite_status=@"1";
    }else if ([self.statusSelectedView.text isEqualToString:@"未生效"]){
        invite_status=@"0";
    }else{
        invite_status=@"3";
    }
    NSString*date;
    if ([self.timeSelectedView.text isEqualToString:@"全部"]) {
        date=@"0";
    }else if ([self.timeSelectedView.text isEqualToString:@"近半年"]){
        date=@"1";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一个月"]){
        date=@"2";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一周"]){
        date=@"3";
    }else if ([self.timeSelectedView.text isEqualToString:@"近三个月"]){
        date=@"4";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一年"]){
        date=@"5";
    }else{
        date=@"0";
    }
    NSDictionary *param= @{@"page":@(self.pageNo),
                           @"page_size":@(self.pageSize),
                           @"invite_status":invite_status,
                           @"date":date,
                           @"display":@"2",
                           
                           };
    [LSRequestManager getRequestWithURL:HUOBI(@"index.php/api/activity/inviteRecord")
                                 params:param
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        self.directLabel.text=[NSString stringWithFormat:@"%@",responseData[@"data"][@"direct"]];
                                        self.indirectLabel.text=[NSString stringWithFormat:@"%@",responseData[@"data"][@"indirect"]];
                                        self.rule=[NSString stringWithFormat:@"%@",responseData[@"data"][@"rule"]];
                                        
                                        InviteView *inviteView = [InviteView xib];
                                        [[UIApplication sharedApplication].keyWindow addSubview:inviteView];
                                        self.inviteView=inviteView;
                                        inviteView.invitesignlabel.text=[NSString stringWithFormat:@"%@",responseData[@"data"][@"invite_code"]];
                                        
                                        inviteView.submitActionBlock = ^(NSInteger tag) {
                                            
                                            
                                            NSLog(@"分享");
                                        };
                                        
                                        
                                    } else {
                                        self.directLabel.text=@"";
                                        self.indirectLabel.text=@"";
                                        [MBProgressHUD showError:responseData[@"msg"]];
                                    }
                                }
                                failure:^(NSError *error) {
                                    self.directLabel.text=@"";
                                    self.indirectLabel.text=@"";
                                }
                                showHUD:NO];
}

- (void)refresh {
    NSLog(@"shoudao");
    [self.recordTV setContentOffset:CGPointMake(0,0) animated:YES];
    
}
-(WHCView *)topview
{
    
    if (!_topview) {
        _topview = [[WHCView alloc]initWithFrame:CGRectMake(20, 391, ScreenWidth-200-20, 30)];
        _topview.backgroundColor = [UIColor clearColor];
        _topview.tabBarBtnBlock = ^(NSInteger btnTag) {
//            [weakSelf scrollToPointFrame:btnTag];
            self.pageNo=1;
            self.selectedTag=btnTag;
            
            //切换邀请记录  返佣记录
            if (btnTag==0) {
                //邀请记录
                [self.timeSelectedView close];
                [self.timeSelectedView removeFromSuperview];
                HWDownSelectedView *down = [HWDownSelectedView new];
                down.backgroundColor = [UIColor clearColor];
                down.textColor = [UIColor colorWithHexString:@"#999999"];
                down.font = [UIFont boldSystemFontOfSize:12];
                down.placeholder = @"全部时间";
                down.listArray = @[@"全部时间", @"近一周", @"近一月", @"近三个月", @"近半年", @"近一年"];
                down.frame = CGRectMake(ScreenWidth-200, 390, 100, 36);
                down.layer.borderWidth = 1;
                down.layer.borderColor = RGBColor(46, 49, 69).CGColor;
                self.timeSelectedView = down;
                [self.headV addSubview:self.timeSelectedView];
                self.timeSelectedView.delegate=self;
                
                [self.statusSelectedView close];
                [self.statusSelectedView removeFromSuperview];
                HWDownSelectedView *statusSelectedView = [HWDownSelectedView new];
                statusSelectedView.backgroundColor = [UIColor clearColor];
                statusSelectedView.textColor = [UIColor colorWithHexString:@"#999999"];
                statusSelectedView.font = [UIFont boldSystemFontOfSize:12];
                statusSelectedView.placeholder = @"全部";
                statusSelectedView.listArray =  @[@"全部",@"已生效", @"未生效"];
                statusSelectedView.frame = CGRectMake(ScreenWidth-100, 390, 80, 36);
                statusSelectedView.layer.borderWidth = 1;
                statusSelectedView.layer.borderColor = RGBColor(46, 49, 69).CGColor;
                self.statusSelectedView = statusSelectedView;
                [self.headV addSubview:self.statusSelectedView];
                self.statusSelectedView.delegate=self;
                
                [self requstInviteRecordData];
            }else if (btnTag==1){
                //返佣记录
                [self.timeSelectedView close];
                [self.timeSelectedView removeFromSuperview];
                HWDownSelectedView *down = [HWDownSelectedView new];
                down.backgroundColor = [UIColor clearColor];
                down.textColor = [UIColor colorWithHexString:@"#999999"];
                down.font = [UIFont boldSystemFontOfSize:12];
                down.placeholder = @"全部时间";
                down.listArray = @[@"全部时间", @"近一周", @"近一月", @"近三个月", @"近半年", @"近一年"];
                down.frame = CGRectMake(ScreenWidth-200, 390, 100, 36);
                down.layer.borderWidth = 1;
                down.layer.borderColor = RGBColor(46, 49, 69).CGColor;
                self.timeSelectedView = down;
                [self.headV addSubview:self.timeSelectedView];
                self.timeSelectedView.delegate=self;
                
                [self.statusSelectedView close];
                [self.statusSelectedView removeFromSuperview];
                HWDownSelectedView *statusSelectedView = [HWDownSelectedView new];
                statusSelectedView.backgroundColor = [UIColor clearColor];
                statusSelectedView.textColor = [UIColor colorWithHexString:@"#999999"];
                statusSelectedView.font = [UIFont boldSystemFontOfSize:12];
                statusSelectedView.placeholder = @"全部";
                statusSelectedView.listArray =  @[@"全部",@"已到账", @"统计中"];
                statusSelectedView.frame = CGRectMake(ScreenWidth-100, 390, 80, 36);
                statusSelectedView.layer.borderWidth = 1;
                statusSelectedView.layer.borderColor = RGBColor(46, 49, 69).CGColor;
                self.statusSelectedView = statusSelectedView;
                [self.headV addSubview:self.statusSelectedView];
                self.statusSelectedView.delegate=self;

                [self getAllCommissionDiscountRecord];
            }
            [self scrollToPointFrame:btnTag];
        };
    }
    return _topview;
}
-(void)beginToRequestCommissionData{
    self.pageNo++;
    [self getAllCommissionDiscountRecord];
}
-(void)getAllCommissionDiscountRecord{
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(beginToRequestCommissionData)];
    //    [footer setTitle:@"点击或下拉加载更多" forState:MJRefreshStateIdle];
    [footer setTitle:@"加载中" forState:MJRefreshStateRefreshing];
    footer.stateLabel.textColor = RGBColor(153, 153, 153);
    self.footer = footer;
    
    NSString*invite_status;
    if ([self.statusSelectedView.text isEqualToString:@"全部"]) {
        invite_status=@"0";
    }else if ([self.statusSelectedView.text isEqualToString:@"已到账"]){
        invite_status=@"1";
    }else if ([self.statusSelectedView.text isEqualToString:@"统计中"]){
        invite_status=@"2";
    }else{
        invite_status=@"0";
    }
    NSString*date;
    if ([self.timeSelectedView.text isEqualToString:@"全部"]) {
        date=@"0";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一周"]){
        date=@"1";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一个月"]){
        date=@"2";
    }else if ([self.timeSelectedView.text isEqualToString:@"近三个月"]){
        date=@"3";
    }else if ([self.timeSelectedView.text isEqualToString:@"近半年"]){
        date=@"4";
    }else if ([self.timeSelectedView.text isEqualToString:@"近一年"]){
        date=@"5";
    }else{
        date=@"0";
    }
    NSDictionary *param= @{@"pageNum":@(self.pageNo),
                           @"pageSize":@(self.pageSize),
                           @"userId":self.useId,
                           @"commissionDiscountTime":date,
                           @"commissionDiscountStatus":invite_status,
                           
                           };
    [LSRequestManager postRequestWithURL:MARKET(@"getCommissionDiscountRecord")
                                 params:param
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        if (self.pageNo==1) {
                                            [self.dataArray removeAllObjects];
                                        }
                                        NSArray *array = [CommissionRecordModel mj_objectArrayWithKeyValuesArray:responseData[@"data"][@"inviteCommissionDiscountRecordVO"]];
                                        [self.dataArray addObjectsFromArray:array];
                                        if (array.count < self.pageSize) {
                                            self.recordTV.mj_footer = self.nilFooter;
                                        } else {
                                            self.recordTV.mj_footer = self.footer;
                                            //                                            self.footer.refreshingTitleHidden = YES;
                                        }
                                        [self.recordTV.mj_footer endRefreshing];
                                        [self.recordTV reloadData];
                                        
                                        
                                        
                                        
                                    } else {
                                        [self.dataArray removeAllObjects];
                                        self.recordTV.mj_footer = self.nilFooter;
                                        [self.recordTV reloadData];
                                        [MBProgressHUD showError:responseData[@"msg"]];
                                    }
                                }
                                failure:^(NSError *error) {
                                    [self.dataArray removeAllObjects];
                                    self.recordTV.mj_footer = self.nilFooter;
                                    [self.recordTV reloadData];
                                }
                                showHUD:NO];
}
-(void)scrollToPointFrame:(NSInteger)tag
{
    for (UIButton *btn in self.topview.tabBtnArray){
        if (btn.tag == tag) {
            [btn setTitleColor:RGBColor(123, 78, 225) forState:UIControlStateNormal];
        }else
        {
            [btn setTitleColor:RGBColor(153, 153, 153) forState:UIControlStateNormal];
        }
    }
//    [self.scrollView setContentOffset:CGPointMake(ScreenWidth*tag, 0) animated:YES];
}
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 431, ScreenWidth, ScreenHeight)];
        _scrollView.pagingEnabled = YES;
        _scrollView.bounces = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(ScreenWidth * self.homeScrollViews.count, ScreenHeight-431);
        
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Me" bundle:nil];
        
        InviteRecoedTableViewController *idea = [story instantiateViewControllerWithIdentifier:@"InviteRecoedTableViewController"];
        idea.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        [self addChildViewController:idea];
        [_scrollView addSubview:idea.view];
        [idea didMoveToParentViewController:self];
        
        CommissionRecordTableViewController *idea1 = [story instantiateViewControllerWithIdentifier:@"CommissionRecordTableViewController"];
        idea1.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight);
        [self addChildViewController:idea1];
        [_scrollView addSubview:idea1.view];
        [idea1 didMoveToParentViewController:self];
       
        
        
        
        
        
        
        [_scrollView setContentOffset:CGPointMake(ScreenWidth*0, 0) animated:YES];
    }
    return _scrollView;
}
- (NSArray<UIViewController *> *)homeScrollViews
{
    if (!_homeScrollViews) {
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Me" bundle:nil];
        
        InviteRecoedTableViewController *vc1 = [story instantiateViewControllerWithIdentifier:@"InviteRecoedTableViewController"];
        CommissionRecordTableViewController *vc2 = [story instantiateViewControllerWithIdentifier:@"CommissionRecordTableViewController"];
        
        _homeScrollViews = [NSArray arrayWithObjects:vc1,vc2, nil];
    }
    return _homeScrollViews;
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == _scrollView) {
        NSInteger offset = scrollView.contentOffset.x;
        for (int i = 0; i < self.homeScrollViews.count; i++) {
            if (offset == ScreenWidth * i) {
                [self scrollToPointFrame:i];
            }
        }
    }
}
- (void)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)clickAction:(UIButton *)button {
    NSLog(@"跳转规则页面");
    [self performSegueWithIdentifier:@"ruleSegue" sender:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"ruleSegue"]) {
        RuleViewController *ruleVC = segue.destinationViewController;
        ruleVC.rule = self.rule;
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView==self.recordTV) {
        return 1;
    }

    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([tableView isEqual:self.recordTV]) {
        return self.dataArray.count;
    }

    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.recordTV]) {
        if (self.selectedTag==0) {
            return 73;
        }else{
            return 96;
        }
    }
    return 0;
    
}
//HWDownSelectedViewDelegate
- (void)downSelectedView:(HWDownSelectedView *)selectedView didSelectedAtIndex:(NSIndexPath *)indexPath{
    self.pageNo=1;
    if (self.selectedTag==0) {//邀请记录
        [self requstInviteRecordData];
    }else{//返佣记录
        [self getAllCommissionDiscountRecord];
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([tableView isEqual:self.recordTV]) {
        if (self.selectedTag==0) {
            InviteRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InviteRecordCell" forIndexPath:indexPath];
            if (cell == nil) {
                cell = [[InviteRecordCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InviteRecordCell"];
            }
            InviteModel*InviteModel=self.dataArray[indexPath.row];
            cell.invite_statusLabel.text=InviteModel.invite_status;
            cell.user_accountLabel.text=InviteModel.user_account;
            cell.create_timeLabel.text=InviteModel.create_time;
            cell.status_levelLabel.text=InviteModel.status_level;
            return cell;
        }else{
            CommissionRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommissionRecordCell" forIndexPath:indexPath];
            if (cell == nil) {
                cell = [[CommissionRecordCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CommissionRecordCell"];
            }
            return cell;
        }
    }
    return nil;
    
}
- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}
-(void)viewWillDisappear:(BOOL)animated{
    if (self.inviteView) {
        [self.inviteView removeFromSuperview];
    }
    
}
- (IBAction)allCommssionAction {
    BillboardListViewController *vc = [[BillboardListViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}
@end
